<template>
  <div class="nav-bar van-hairline--top">
    <ul class="nav-list">
      <router-link tag="li" class="nav-list-item active" to="home">
        <van-icon
          class="iconfont"
          class-prefix="icon"
          name="icon_ruixingkafei1"
        />
        <span>首页</span>
      </router-link>
      <router-link tag="li" class="nav-list-item" to="category">
        <van-icon class="iconfont" class-prefix="icon" name="cup" />
        <span>菜单</span>
      </router-link>
      <router-link tag="li" class="nav-list-item" to="order">
        <van-icon class="iconfont" class-prefix="icon" name="icon-order-copy" />
        <span>订单</span>
      </router-link>
      <router-link tag="li" class="nav-list-item" to="cart">
        <van-icon class="iconfont" class-prefix="icon" name="gouwuche-copy" />
        <span>购物车</span>
      </router-link>
      <router-link tag="li" to="user" class="nav-list-item">
        <van-icon class="iconfont" class-prefix="icon" name="wode" />
        <span>我的</span>
      </router-link>
    </ul>
  </div>
</template>

<script>
import { getLocal } from "@/common/js/utils";
import { computed, onMounted } from "vue";
import { useRoute } from "vue-router";
import { useStore } from "vuex";
export default {
  setup() {
    const route = useRoute();
    const store = useStore();
    onMounted(() => {
      const token = getLocal("token");
      const path = route.path; // 当前页面的路由
      if (token && !["/home", "/category"].includes(path)) {
        // 已登录的情况下做页面跳转
        store.dispatch("updateCart");
      }
    });
    const count = computed(() => {
      return store.state.cartCount;
    });

    return {
      count,
    };
  },
};
</script>

<style lang="less" scoped >
@import "../common/style/mixin";
.nav-bar {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  padding: 5px 0;
  z-index: 100;
  background: #f8f8f8;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  border-top: 2px solid #e7e7e7;
  .nav-list {
    width: 100%;
    .fj();
    flex-direction: row;
    padding: 0;
    .nav-list-item {
      display: flex;
      flex: 1;
      flex-direction: column;
      text-align: center;
      color: #666;
      &.router-link-active {
        color: @primary;
      }
      i {
        text-align: center;
        font-size: 22px;
      }
      img {
        text-align: center;
        font-size: 22px;
      }
      span {
        font-size: 12px;
      }
      .van-icon {
        margin: 0 auto;
        margin-bottom: 2px;
      }
    }
  }
}
</style>
  